<?php
/**
 * Transaction manager
 * Database transaction
 * @author HoanVX
 * @version $Id$
 */
class DBTransaction {
	
	private $wpdb;
	function  __construct() {
		global $wpdb;
		$this->wpdb = $wpdb;
	}
	
	/**
	 * Start transaction before call insert/update/delete database
	 * @return Ambigous <number, false>
	 */
	public function beginTransaction() {
		return $this->wpdb->query("START TRANSACTION;");
	}

	public function queryException($error) {
		if(!empty($error)){
			throw new Exception("SQL ERRORS");
		}
	}
	
	/**
	 * Commit section if these processes before that successful
	 * @return Ambigous <number, false>
	 */
	public function commit() {
		return $this->wpdb->query("COMMIT;");
	}
	
	/**
	 * Rollback transaction if error is occur
	 * @return Ambigous <number, false>
	 */
	public function rollBack() {
		return $this->wpdb->query("ROLLBACK;");
	}
}